{% extends 'subpage/base.html' %}
{% block table %}
    <div class="top-name">
        <div class="row">
            <div class="col-xs-6">
                <span class="col-xs-4 name-title">值班三线：</span>
                <strong class="col-xs-6 third-name-text"></strong>
            </div>
            <div class="col-xs-6">
                <span class="col-xs-4 name-title">值班四线：</span>
                <strong class="col-xs-6 forth-name-text"></strong>
            </div>
        </div>
    </div>
    <div class="show-input-items clearfix">
        <table class="table table-bordered">
        </table>
    </div>
{% endblock %}
{% block return_block %}
    <div class="btn-return-back">
        <button class="btn btn-info" onclick="window.location.href='/thirdline'">返回</button>
    </div>
{% endblock %}
{% block time_field %}
    {% if current_user.is_authenticated and current_user.the_group.name == "LEVEL3" %}
        <a href="javascript:;" class="pull-right report-entrance">生成报告</a>
    {% endif %}
{% endblock %}
{% block ueditorbox %}
    <div class="select-depart">
        <div class="form-group clearfix">
            <label for="selectDepart" class="control-label col-xs-1 depart-desc" style="color: #333;">部门：</label>
            <div class="col-xs-8">
                <select name="selectDepart" id="selectDepart" class="form-control"></select>
            </div>
        </div>
    </div>
    <div class="show-duty">
        <div class="duty-content">

        </div>
    </div>
{% endblock %}
{% block content %}
    {{ super() }}
    <script>
        $(function () {
            var dutyId = GetQueryString('dutyId'), departId = GetQueryString('departId'), dutyTime;
            var data = {
                "dutyId": dutyId,
                "departId": departId,
                "level": 3
            };
            //判断返回的目的地
            if (parseInt(GetQueryString("isme"))) {
                $(".btn-return-back").html("<button class='btn btn-info' onclick=\"window.location.href='/myThirdlist'\">返回</button>");
            } else if (!parseInt(GetQueryString("isme"))) {
                $(".btn-return-back").html("<button class='btn btn-info' onclick=\"window.location.href='/thirdline'\">返回</button>");
            }
            //动态标题
            var title = "<span class='duty_time'>" + GetQueryString("duty_time") + "</span>&nbsp;&nbsp;&nbsp;" + GetQueryString("departAlias") + "&nbsp;&nbsp;&nbsp;三线值班报告";//如果编辑状态的话应该放在ajax success回调的方法下
            $('.title-text').html(title);

            $(".report-entrance").click(function () {
                window.location.href = '/produceReport?dutyId=' + GetQueryString("dutyId") + "&level=3";
            });
            function success(data) {
                if (data.onDutyThirdName) {
                    $('.third-name-text').html(data.onDutyThirdName);
                } else {
                    $('.third-name-text').parents('.col-xs-6').css('display', 'none');
                }
                if (data.onDutyForthName) {
                    $('.forth-name-text').html(data.onDutyForthName);
                } else {
                    $('.forth-name-text').parents('.col-xs-6').css('display', 'none');
                }
                dutyTime = data.richTextTime;
                if (data.tableList.length > 0) {
                    var str = '';
                    str += '<thead><tr><th>时间</th><th>故障内容</th><th>故障说明</th></tr></thead><tbody>';
                    for (var i = 0; i < data.tableList.length; i++) {
                        var item = data.tableList[i];
                        str += '<tr><td>' + item.brokeTime + '</td><td>' + item.brokeContent + '</td><td>' + item.brokeDeal + '</td></tr>';
                    }
                    $('.table').html(str);
                }
                loadAllDeparts();
            }

            function error(error) {
                $.myAlert({title: '出错提示', message: '请求出错！'});
            }

            ajaxRequest('GET', GLOBAL_VARIABLE.BASE_URL + '/datashow', data, success, error, '{{ csrf_token }}');
            function loadAllDeparts() {
                ajaxRequest('GET', '/groups', {"viewDetail": 0}, success, error, '{{ csrf_token }}');
                function success(data) {
                    var str = '<option data-departId="0">--请选择--</option>';
                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        if (item.departName !== "LEVEL3") {
                            str += '<option data-departId="' + item.departId + '" data-departName="' + item.departName + '">' + item.departAlias + '</option>';
                        }
                    }
                    $('#selectDepart').html(str);
                }

                function error() {
                    $.myAlert({title: '出错提示', message: '加载部门出错,请重新加载'});
                }
            }

            //点击部门，查询相应的二线内容
            $('#selectDepart').change(function () {
                var departId = $("#selectDepart option:selected").attr("data-departId"),
                    departName = $("#selectDepart option:selected").attr("data-departName"), data = {};
                data = {
                    "departId": departId,
                    "departName": departName,
                    "time": dutyTime
                };
                if (data.departId === "0") {
                    $('.duty-content').html("");
                } else {
                    ajaxRequest("GET", GLOBAL_VARIABLE.BASE_URL + "/threeshowtwo", data, success, error, "{{ csrf_token }}");
                }
                function success(data) {
                    //判断是否有table
                    if (data.tableList.length > 0) {//table有数据
                        if (data.tableList[0].idc) {//判断是系统运维部
                            var str1 = '';
                            str1 += "<table class='table table-bordered'><thead><tr><th>机房位置</th><th>带宽值(Mb/s)</th></tr></thead><tbody>";
                            for (var i = 0; i < data.tableList.length; i++) {
                                var item = data.tableList[i];
                                str1 += '<tr><td>' + item.idc + '</td><td>' + item.bw + '</td></tr>';
                            }

                            str1 += '</tbody></table><div class="show-duty-ueditor">' + data.richText + '</div>';
                            $('.duty-content').html(str1);

                        } else if (data.tableList[0].event) {//判断是网络安全部
                            var str2 = '';
                            str2 += "<table class='table table-bordered'><thead><tr><th>事件</th><th>类型</th><th>时间</th><th>说明</th></tr></thead><tbody>";
                            for (var j = 0; j < data.tableList.length; j++) {
                                var item2 = data.tableList[j];
                                str2 += '<tr><td>' + item2.event + '</td><td>' + item2.type + '</td><td>' + item2.time + '</td><td>' + item2.content + '</td></tr>';
                            }
                            str2 += '</tbody></table><div class="show-duty-ueditor">' + data.richText + '</div>';
                            $('.duty-content').html(str2);
                        } else {//其他部门
                            $('.duty-content').html(data.richText);
                        }
                    } else {
                        $('.duty-content').html(data.richText);
                    }
                }

                function errot(err) {
                    $.myAlert({title: '出错提示', message: "请求出错！"});
                }
            });
        });
    </script>
{% endblock %}